<script>
	import {
		login,
		clickChannel,
		sendSmsCode,
		checkChannelV1,
		oldRegisterV5,
		analysis
	} from "@/api/index.js";
	export default {
		onLaunch: function() {
			
		},
		onShow: async function() {
			// uni.reLaunch({
			// 	url:'/pagesC/list/index'
			// })
			const url = window.location.href;
			// console.log(url,'url')
			// let url = "http://192.168.1.52:8081/#/";
			// let url="https://test.h5.jht.cash/push/?channelId=BrSRvA4S#/?channelId=BrSRvA4S&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxMDQifQ.y8j0JcrP6ZPPtG8lp-ftpZ39YRGHgPbn3PkhVpnplmw"
			// 链接是有#的
			// let url="http://localhost:8080?channelId=BrSRvA4S#/pagesC/list/index"
			// let url ="https://test.h5.jht.cash/push/?channelId=morens#/?channelId=morens&pages=/pages/list/index&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxMjMifQ.hFKk4VPHp-5UvBwP_7QFEWiqxfwqcPz_l_wcXi3Cllk"
			// 将链接的#去除
			let howMach=this.countCharactersWithSplit(url,'?');
			let url1=''
			if(howMach==2){
				 url1 = url.replace(/#\//g, '')
			}else{
				 url1 = url
			}
			// console.log(howMach,'howMach');
			// let url1 = url.replace(/#\//g, '')
			// console.log(url1,'url1')
			let params = new URLSearchParams(new URL(url1).search);
			let param1 = params.get('channelid');
			let pages = params.get('pages');
			let param3 = params.get('token');
			// console.log(param1,'param1')
			param1 = this.cutBeforeChar(param1, "?"); // 返回 "Hello"
			uni.setStorageSync('channelid', param1);
			// console.log(param1,'param1')
			if (param3 == null) {
				var pre = JSON.stringify(performance);
				// await analysis({
				// 	"preformance": pre
				// })
				// 如果没有token  原始链接
			} else {
				// 有token  那就是连登
				
				uni.setStorageSync('token', param3);
				
				uni.reLaunch({
					url: pages,
				})
				let a1 = await clickChannel({
					type: 1
				})
				if (a1.code == 100000) {
					let a2 = await clickChannel({
						type: 2
					})
					if (a2.code == 100000) {
						await clickChannel({
							type: 10
						})
			
					}
				}
			
				
				
				return;
			
			
			}
			// // plus.navigator.closeSplashscreen();
			
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			countCharactersWithSplit(str, char) {
			    return (str.split(char).length - 1); // 因为分割后数组的元素个数比字符数多1（最后一个元素是空字符串）
			},
			closeSplash() {
				// plus.navigator.closeSplashscreen();
			},
			cutBeforeChar(str, char) {
				if (str) {
					var index = str.indexOf(char);
					if (index != -1) {
						return str.substring(0, index);
					}
				}
				
				return str;
			},
		
		}
	}
</script>

<style>
	/*每个页面公共css */
	.dis {
		display: flex;
	}

	@font-face {
		font-family: "DIN";
		src: url("@/static/DIN-Bold/din-bold-2.ttf")
	}

	.DIN {
		font-family: 'DIN' !important;
	}
</style>